package com.huawei.appmarket.service.usercenter.userinfo.view.activity;

import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import com.huawei.appgallery.foundation.ui.framework.cardframe.fragment.TaskFragment;
import com.huawei.appgallery.foundation.ui.framework.fragment.LoadingFragment;
import com.huawei.appgallery.foundation.ui.framework.titleframe.bean.BaseTitleBean;
import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean;
import com.huawei.appmarket.framework.titleframe.title.BackTitle;
import com.huawei.appmarket.service.usercenter.userinfo.bean.CountryInfo;
import com.huawei.appmarket.service.usercenter.userinfo.bean.CountryInfoQueryRes;
import com.huawei.hwid.core.constants.HwAccountConstants;
import com.huawei.secure.android.common.intent.SafeBundle;
import com.huawei.secure.android.common.intent.SafeIntent;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import o.ayy;
import o.azb;
import o.cvt;
import o.der;
import o.der.a;
import o.der.d;
import o.der.g;
import o.dgm;
import o.Logger;
import o.ContentManager;
import o.emd;
import o.emf;
import o.emm.b;
import o.emm.e;
import o.emq;
import o.ewm.j;
import o.eyo;
import o.FragmentTransaction;

public class ChooseCountryCommonActivity extends FragmentActivity implements e, TaskFragment.e {
    private b ʻॱ = null;
    protected RelativeLayout ˊॱ;
    private SearchBar ˋॱ = null;
    private ListView ˏॱ = null;
    protected LinearLayout ͺ;
    private ChooseCountryAdapter ॱˊ = null;
    private TextView ॱˋ = null;
    private TextView ॱᐝ;
    private TextView ᐝॱ;

    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        getWindow().setBackgroundDrawableResource(a.ᐝ);
        ayy.ˋ().ˎ(getWindow());
        setContentView(g.ˋˊ);
        ˋ(getTitle());
        this.ˏॱ = (ListView) findViewById(d.ʻᐝ);
        this.ˊॱ = (RelativeLayout) findViewById(d.ʽᐝ);
        this.ˋॱ = (SearchBar) findViewById(d.ꜟ);
        this.ͺ = (LinearLayout) findViewById(d.ʼʼ);
        this.ॱᐝ = (TextView) findViewById(d.ʼˋ);
        this.ᐝॱ = (TextView) findViewById(d.ʽˊ);
        String string = new SafeBundle(new SafeIntent(getIntent()).getExtras()).getString("country_phone_info_of_user");
        if (string == null || string.isEmpty()) {
            this.ͺ.setVisibility(8);
        } else {
            this.ͺ.setVisibility(0);
            List ॱ = ॱ(string);
            this.ॱᐝ.setText((CharSequence) ॱ.get(0));
            this.ᐝॱ.setText((CharSequence) ॱ.get(1));
        }
        ॱˊ();
        ᐝ();
    }

    private List<String> ॱ(String str) {
        List<String> arrayList = new ArrayList(Arrays.asList(str.split("\\+")));
        arrayList.set(0, ((String) arrayList.get(0)).replace(HwAccountConstants.BLANK, ""));
        return arrayList;
    }

    public void onConfigurationChanged(Configuration configuration) {
        super.onConfigurationChanged(configuration);
        ॱˊ();
    }

    private void ॱˊ() {
        View findViewById = findViewById(d.ʾॱ);
        View findViewById2 = findViewById(d.ʻˋ);
        Context ˋ = ContentManager.getInstant().getContext();
        if (azb.ʼ(ˋ)) {
            azb.ॱ(findViewById);
            azb.ʻ(findViewById2);
            azb.ʻ(this.ˋॱ);
            return;
        }
        azb.ʼ(findViewById, ˋ.getResources().getDimensionPixelOffset(der.b.ʼ));
        azb.ॱॱ(findViewById2, ˋ.getResources().getDimensionPixelOffset(der.b.ʻ));
        azb.ॱॱ(this.ˋॱ, 2);
    }

    private void ˋ(CharSequence charSequence) {
        if (charSequence == null) {
            Logger.e("ChooseCountryCommonActivity", "error title.");
            return;
        }
        View findViewById = findViewById(j.ˇˊ);
        if (findViewById instanceof ViewGroup) {
            ViewGroup viewGroup = (ViewGroup) findViewById;
            BaseTitleBean baseTitleBean = new BaseTitleBean();
            baseTitleBean.ॱ(charSequence.toString());
            View ˋ = new BackTitle(this, baseTitleBean).ˋ();
            if (ˋ != null) {
                viewGroup.setVisibility(0);
                viewGroup.addView(ˋ);
            }
        }
    }

    protected void ʼ() {
        this.ˋॱ.setTvDialog(this.ॱˋ);
        if ("CN".equalsIgnoreCase(getResources().getConfiguration().locale.getCountry()) || "EN".equalsIgnoreCase(getResources().getConfiguration().locale.getLanguage())) {
            this.ˋॱ.setVisibility(0);
        } else {
            this.ˋॱ.setVisibility(8);
        }
        this.ˋॱ.setOnTouchLetterChangeListener(new SearchBar.a(this) {
            final /* synthetic */ ChooseCountryCommonActivity ˊ;

            {
                this.ˊ = r1;
            }

            public void ˋ(String str) {
                this.ˊ.ʻॱ.ˋ(str);
            }
        });
        this.ˋॱ.requestFocus();
    }

    private void ͺ() {
        this.ˏॱ.setOnItemClickListener(new OnItemClickListener(this) {
            final /* synthetic */ ChooseCountryCommonActivity ˋ;

            {
                this.ˋ = r1;
            }

            public void onItemClick(AdapterView<?> adapterView, View view, int i, long j) {
                emf item = this.ˋ.ॱˊ.getItem(i);
                if (item != null && item.ˎ() != 0) {
                    this.ˋ.ˋ(view);
                }
            }
        });
    }

    protected void ᐝ() {
        this.ˊॱ.setVisibility(0);
        this.ˏॱ.setVisibility(8);
        Fragment loadingFragment = new LoadingFragment();
        FragmentTransaction ˊ = ˏॱ().ˊ();
        ˊ.ˏ(d.ʽᐝ, loadingFragment, "InfoGetLoadTag");
        ˊ.ˋ();
    }

    protected void ॱॱ() {
        this.ˊॱ.setVisibility(8);
        this.ˏॱ.setVisibility(0);
    }

    public boolean ˋ(TaskFragment taskFragment, TaskFragment.b bVar) {
        if (bVar.ˋ.getResponseCode() == 0 && bVar.ˋ.getRtnCode_() == 0) {
            ResponseBean responseBean = bVar.ˋ;
            if (responseBean instanceof CountryInfoQueryRes) {
                ˋ(ˎ(((CountryInfoQueryRes) responseBean).ˏ()));
                ॱॱ();
            }
        } else if (taskFragment instanceof LoadingFragment) {
            LoadingFragment loadingFragment = (LoadingFragment) taskFragment;
            eyo ॱ = eyo.ॱ(bVar.ˊ, bVar.ˋ, null);
            loadingFragment.ˏ(ॱ.ˊ(), ॱ.ᐝ());
        }
        return false;
    }

    public void ˎ(TaskFragment taskFragment, List<cvt> list) {
        cvt o_emd = new emd();
        o_emd.setServiceType_(dgm.ˎ(this));
        list.add(o_emd);
    }

    protected void ˋ(View view) {
        Object tag = view.getTag();
        if (tag instanceof d) {
            d dVar = (d) tag;
            Intent intent = new Intent();
            intent.putExtra("selected_country_phone_info", dVar.ˋ.getText().toString() + "  +" + dVar.ॱ.getText().toString());
            setResult(1126, intent);
            finish();
        }
    }

    protected void ˋ(List<emf> list) {
        this.ʻॱ = new emq(this);
        this.ॱˋ = (TextView) findViewById(d.ˈˊ);
        ʼ();
        ˏ(list);
        ͺ();
    }

    protected void ˏ(List<emf> list) {
        this.ʻॱ.ˎ(list);
    }

    public void ॱ(List<emf> list) {
        if (this.ॱˊ == null) {
            this.ॱˊ = new ChooseCountryAdapter(this, list);
            this.ˏॱ.setAdapter(this.ॱˊ);
        } else {
            this.ॱˊ.updateList(list);
        }
        this.ˏॱ.setOnScrollListener(new OnScrollListener(this) {
            final /* synthetic */ ChooseCountryCommonActivity ˋ;

            {
                this.ˋ = r1;
            }

            public void onScrollStateChanged(AbsListView absListView, int i) {
            }

            public void onScroll(AbsListView absListView, int i, int i2, int i3) {
                if (this.ˋ.ˋॱ.getVisibility() == 0 && this.ˋ.ॱˊ != null && absListView != null && this.ˋ.ॱˊ.getItem(absListView.getFirstVisiblePosition()) != null) {
                    this.ˋ.ˋॱ.ॱ(this.ˋ.ॱˊ.getItem(absListView.getFirstVisiblePosition()).ˊ());
                }
            }
        });
    }

    public void ˎ(int i) {
        this.ˏॱ.setSelection(i);
    }

    public static ArrayList<emf> ˎ(List<CountryInfo> list) {
        ArrayList<emf> arrayList = new ArrayList();
        if (!(list == null || list.isEmpty())) {
            for (int i = 0; i < list.toArray().length; i++) {
                emf o_emf = new emf();
                o_emf.ˋ(((CountryInfo) list.get(i)).ˏ());
                o_emf.ˏ(((CountryInfo) list.get(i)).ॱ());
                arrayList.add(o_emf);
            }
        }
        return arrayList;
    }
}
